package cn.edu.util;

import cn.edu.entity.Province;
import cn.edu.entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class ProvinceUtil {


    public static List<Province> getList(String sql, Object... objs)throws Exception{
        List<Province> list = new ArrayList<>();
        Connection conn = DBUtil.getConnection();
//        "select * from tb_user where name=? and password=?";
        PreparedStatement prestat = conn.prepareStatement(sql);
        if(objs!=null){
            for (int i = 0; i < objs.length; i++) {
                prestat.setObject(i+1,objs[i]);//eitity实体类定义数据,建议都是包装类.
            }
        }
        ResultSet rs = prestat.executeQuery();
        while(rs.next()){
            Province province = new Province();
            province.setId((Integer) rs.getObject(1));
            province.setName(rs.getString(2));
            list.add(province);
        }
        DBUtil.close(conn,prestat,rs);
        return list;
    }

}
